//
//  CLGCD.m
//  CLBasicsDemo
//
//  Created by 小草毋正 on 2017/9/13.
//  Copyright © 2017年 zbw. All rights reserved.
//

#import "CLGCD.h"

@implementation CLGCD


/** 获取主线程 */
+ (void)mainQueue:(void(^)(void))block {
    dispatch_async(dispatch_get_main_queue(), block);
}

/** 在一段时间后到主线程执行 */
+ (void)mainQueueAfter:(double)time block:(void(^)(void))block {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
}

/** 获取低优先级全局队列线程 */
+ (void)globalQueueLowAsync:(void(^)(void))block{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), block);
}

/** 获取高优先级全局队列线程 */
+ (void)globalQueueHigAsync:(void(^)(void))block{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), block);
}

+ (void)userQueueConcurrentName:(NSString *)queueName asyncBlock:(void(^)(void))block {
    static NSMutableDictionary *userQueueDict;
    if(!userQueueDict){
        userQueueDict = [[NSMutableDictionary alloc] init];
    }
    dispatch_queue_t userqueue = [userQueueDict valueForKey:queueName];
    if(userqueue == nil){
        userqueue = dispatch_queue_create([queueName UTF8String], DISPATCH_QUEUE_CONCURRENT);
        [userQueueDict setObject:userqueue forKey:queueName];
    }
    dispatch_async(userqueue, block);
}

+ (void)userQueueSerialname:(NSString *)queueName asyncBlock:(void(^)(void))block {
    static NSMutableDictionary *userQueueDict;
    if(!userQueueDict){
        userQueueDict = [[NSMutableDictionary alloc] init];
    }
    dispatch_queue_t userqueue = [userQueueDict valueForKey:queueName];
    if(userqueue == nil){
        userqueue = dispatch_queue_create([queueName UTF8String], DISPATCH_QUEUE_SERIAL);
        [userQueueDict setObject:userqueue forKey:queueName];
    }
    dispatch_async(userqueue, block);
}





@end

